home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / misc / dspice0s / unix.c < prev    next >
C/C++ Source or Header  |  1993-01-18  |  7KB  |  371 lines

  1. /*
  2.  * SCCSID=unix.c 3/15/83
  3.  */
  4.  
  5. #include <sys/param.h>
  6. #include <stdio.h>
  7. #include <time.h>
  8.  
  9. #ifndef BSD
  10. #    define bcopy(s, d, l) memcpy(d, s, l)
  11. #    define bzero(b, l) memset(b, 0, l)
  12. #endif
  13.  
  14.  
  15. #ifdef mips
  16. #    define xargc f77argc
  17. #    define xargv f77argv
  18. #endif
  19.  
  20. extern    int    xargc;
  21. extern    char    **xargv;
  22.  
  23.  
  24. /*
  25.  * loc_ - return the address of arg
  26.  */
  27. int
  28. loc_( arg )
  29.     int *arg;
  30. {
  31.     return( (int) arg );
  32. }
  33.  
  34.  
  35. /*
  36.  * times_ - c routine to call library routine times
  37.  */
  38. void
  39. times_( iarg )
  40.     int *iarg ;
  41. {
  42. /*    times( iarg );*/
  43.  
  44. /*DJGPP does not have times so must use time */
  45.  
  46.     time( iarg);
  47.     *iarg = *iarg*60;
  48. }
  49.  
  50. /*
  51.  * xtime_ - fortran routine for character time
  52.  */
  53. void
  54. xtime_( chr )
  55.     char *chr;
  56. {
  57.     struct tm    *localtime();
  58.     char        *asctime(),    *character;
  59.     long        time();
  60.     long        tloc,    scum;
  61.     int        i;
  62.  
  63.         tloc = time( & scum );
  64.         character = asctime( localtime(& tloc) );
  65.         for( i = 11; i < 19; i++ )
  66.                 *chr++ = *( character + i );
  67. }
  68.  
  69. /*
  70.  * xdate_ - fortran routine for character date
  71.  */
  72. void
  73. xdate_( chr )
  74.     char    *chr;
  75. {
  76.     struct    tm    *localtime(),    *buffer;
  77.     char        *asctime(),    *month,    *day,    *year,    *itoc();
  78.     long        time();
  79.     long        tloc,    scum;
  80.  
  81.         tloc = time( & scum );
  82.         buffer = localtime( & tloc);
  83.         month = itoc( buffer->tm_mon + 1 );   /* month is zero based */
  84.         while( *month )
  85.                 *chr++ = *month++;
  86.         *chr++ = '\/';
  87.         day = itoc( buffer->tm_mday );
  88.         while( *day )
  89.                 *chr++ = *day++;
  90.         *chr++ = '\/';
  91.         year = itoc( buffer->tm_year );
  92.         while( *year )
  93.                 *chr++ = *year++;
  94. }
  95.  
  96. /*
  97.  * itoc
  98.  */
  99. static char  *
  100. itoc( number )
  101.     int    number;
  102. {
  103.     static char string[3];
  104.  
  105.     /*
  106.      * make a two digit string from the least significant digits of number
  107.      */
  108.         string[2] = '\0';
  109.         string[1] = number%10 + '0';
  110.         number /= 10;
  111.         string[0] = number%10 + '0';
  112.         return( string );
  113. }
  114.  
  115. /*
  116.  * dblsgl - convert a complex double precision array into
  117.  *  a single precision complex array.
  118.  */
  119. void
  120. dblsgl_( cstar16, numwds )
  121.     double    *cstar16;
  122.     int    *numwds;
  123. {
  124. #if 0
  125.     float    *cstar8;
  126.     int    i;
  127.  
  128.     cstar8 = (float *) cstar16;
  129.     for ( i = 0; i < (*numwds)/4; i++ ) {
  130.         cstar8[ i ] = cstar16[ 2*i ];
  131.     }
  132. #endif
  133. }
  134.  
  135. static FILE *rawfile;  /* pointer to raw file  */
  136.  
  137. /*
  138.  * Open raw data file.  Return 1 if file is opened,
  139.  *  return 0 if file is not opened
  140.  */
  141. int
  142. iopraw_()
  143. {
  144.     int    i;
  145.     char    *filename = NULL;/* name of raw file */
  146.  
  147.     for ( i=1; i < xargc; i++ ) {
  148.         if ( *xargv[i] == '-' )
  149.             switch ( xargv[i][1] )  {
  150.             case 'r':
  151.                 if ( ++i < xargc )
  152.                     filename = xargv[i];
  153.                 else
  154.                     filename = "rawspice";
  155.                 break;
  156.             default:
  157.                 fprintf( stderr, "SPICE: illegal option -%c - ignored\n",
  158.                         xargv[i][1] );
  159.                 break;
  160.             }
  161.     }
  162.     if ( filename == NULL )
  163.         return( 0 );
  164.     if  ( (rawfile=fopen( filename, "w" )) == NULL ) {
  165.         fprintf( stderr, "SPICE: unable to open file %s\n", filename );
  166.         fprintf( stderr, "SPICE:  *** program terminated ***\n" );
  167.         exit( 1 );  /* terminate program */
  168.     }
  169.     return( 1 );  /* normal termination */
  170. }
  171.  
  172. /*
  173.  * Close raw file.
  174.  */
  175. void
  176. clsraw_()
  177. {
  178.     fclose( rawfile );
  179. }
  180.  
  181. /*
  182.  * Write into raw file numwds 16 bit words starting
  183.  *  at location data
  184.  */
  185. void
  186. fwrite_( data, numwds )
  187.     char    *data;
  188.     int    *numwds;
  189. {
  190.     fflush( stderr );
  191.     fwrite( data, 2, *numwds, rawfile );
  192.     fflush( rawfile );
  193. }
  194.  
  195. static void mcopy();
  196.  
  197. /*
  198.  * Zero, copy and move for vax unix.
  199.  */
  200. void
  201. move_( array1, index1, array2, index2, length )
  202.     register char    *array1, *array2;
  203.     register int    *length;
  204.     int        *index1, *index2;
  205. {
  206.     array1 += *index1 - 1;
  207.     array2 += *index2 - 1;
  208.     mcopy( array2, array1, *length );
  209. }
  210.  
  211.  
  212. void
  213. zero4_( array, length )
  214.     char        *array;
  215.     unsigned    *length;
  216. {
  217.     bzero( array, *length * 4 );
  218. }
  219.  
  220.  
  221. void
  222. zero8_( array, length )
  223.     char        *array;
  224.     unsigned    *length;
  225. {
  226.     bzero( array, *length * 8 );
  227. }
  228.  
  229.  
  230. void
  231. zero16_( array, length )
  232.     char        *array;
  233.     unsigned    *length;
  234. {
  235.     bzero( array, *length * 8 );
  236. }
  237.  
  238.  
  239. void
  240. copy4_( from, to, length )
  241.     char        *from, *to;
  242.     int        *length;
  243. {
  244.     mcopy( from, to, *length * 4 );
  245. }
  246.  
  247.  
  248. void
  249. copy8_( from, to, length )
  250.     char        *from, *to;
  251.     int        *length;
  252. {
  253.     mcopy( from, to, *length * 8 );
  254. }
  255.  
  256.  
  257. void
  258. copy16_( from, to, length )
  259.     char        *from, *to;
  260.     int        *length;
  261. {
  262.     mcopy( from, to, *length * 8 );
  263. }
  264.  
  265.  
  266.  
  267. #ifdef vax
  268.  
  269. #define VAXMAXSIZE ((2<<15) - 1);
  270.  
  271. /*
  272.  * mcopy - copy memory.
  273.  */
  274. static void
  275. mcopy( from, to, size )
  276.     char        *from,    *to;
  277.     int        size;
  278. {
  279.     register int        i = VAXMAXSIZE;
  280.  
  281.     if ( size < i ) {
  282.         asm( "    movc3 12(ap),*4(ap),*8(ap)" );
  283.         return;
  284.     }
  285.     else if ( from >= to ) {
  286.         for ( ; size > i; size -= i, to += i, from += i ) {
  287.             asm( "    movc3 r11,*4(ap),*8(ap)" );
  288.         }
  289.         asm( "    movc3 12(ap),*4(ap),*8(ap)" );
  290.         return;
  291.     }
  292.     else {
  293.         to   += size;
  294.         from += size;
  295.         size -= i;
  296.         for ( ; size > 0; size -= i ) {
  297.             to   -= i;
  298.             from -= i;
  299.             asm( "    movc3 r11,*4(ap),*8(ap)" );
  300.         }
  301.         size += i;
  302.         to   -= size;
  303.         from -= size;
  304.         asm( "    movc3 12(ap),*4(ap),*8(ap)" );
  305.         return;
  306.     }
  307. }
  308.  
  309. #else
  310.  
  311. /*
  312.  * mcopy - copy memory.
  313.  */
  314. static void
  315. mcopy (from, to, size)
  316.     register char *from, *to;
  317.     register int size;
  318. {
  319.     register char *frome, *toe;
  320.  
  321.     if (size <= 0) return;
  322.  
  323.     frome = from + size;
  324.     if (from >= to || frome <= to) {
  325.     bcopy (from, to, size);
  326.     }
  327.     else {
  328.     /* Source and destination overlap with destination above source.
  329.        Therefore a forward copy will bash later source to be copied.
  330.        Use a backward copy instead. */
  331.     toe = to + size;
  332.     if ((((unsigned)to ^ (unsigned)from) & 3) != 0 || size < 4) {
  333.         /* alignment of source and destination not identical;
  334.            use a simple byte copy. */
  335.         do {
  336.         *--toe = *--frome;
  337.         } while (frome != from);
  338.     }
  339.     else {
  340.         while (((unsigned)toe & 3) != 0) {
  341.         *--toe = *--frome;
  342.         size -= 1;
  343.         }
  344.         size -= 16;
  345.         while (size >= 0) {
  346.         toe -= 16;
  347.         frome -= 16;
  348.         ((int*)toe)[3] = ((int*)frome)[3];
  349.         ((int*)toe)[2] = ((int*)frome)[2];
  350.         ((int*)toe)[1] = ((int*)frome)[1];
  351.         ((int*)toe)[0] = ((int*)frome)[0];
  352.         size -= 16;
  353.         }
  354.         size += 16 - 4;
  355.         while (size >= 0) {
  356.         toe -= 4;
  357.         frome -= 4;
  358.         ((int*)toe)[0] = ((int*)frome)[0];
  359.         size -= 4;
  360.         }
  361.         size += 4;
  362.         while (size > 0) {
  363.         *--toe = *--frome;
  364.         size -= 1;
  365.         }
  366.     }
  367.     }
  368. }
  369. #endif
  370.  
  371.